<?php
class FrameAction extends BaseAction {
	
	//TOP头部，进行版本更新检测
	public function top(){
		$webConfig = WebConfigHelper::getObject();	//系统配置数据
		if(($webConfig["last_check_timeline"]+60*60*24*UpgradeType::$UPGRADE_CHECK_INTERVAL_TIME) <= time()){	//超过检查时间
			//执行检查
			$url = UpgradeType::$UPGRADE_SITE_URL.'index/'.'?k='.urlencode($webConfig["version_number"]);
			$result = json_decode(file_get_contents($url));
			if(!empty($result)){
				if($result->status == 1){	//有补丁情况
					//更新本地配置数据，刷新“最新版本号”、“上次版本号检查时间”。以免每次到该页面，都请求远程数据，会影响双方的网站速度
					$data["latest_version_number"] = $result->data->version_name;
					$data["latest_upgrade_file_addr"] = $result->data->current_upgrade_file_addr;
					$data["last_check_timeline"] = time();
					WebConfigHelper::update($data,"");
				}
			}
			
		}
	}
	
	//FrameSet集
	public function main(){
		$this->display();
	}
	
	//后台默认主页
	public function index(){
		//树状导航栏
		$catalogList = CatalogHelper::getList("pid=0","order_num DESC");
		$subCatalogList = CatalogHelper::getList("pid<>0","order_num DESC");
		$webConfig = WebConfigHelper::getObject();	//系统配置数据
		
		$this->assign("mysql",extension_loaded("mysql"));	//GD组件是否加载
		$this->assign("gd",extension_loaded("gd"));	//GD组件是否加载
		$this->assign("curl",extension_loaded("curl"));	//CURL组件是否加载
		$this->assign("webConfig",$webConfig);
		$this->assign("catalogList",$catalogList);
		$this->assign("subCatalogList",$subCatalogList);
		$this->display();
	}
	
	//清除Runtime文件夹下的所有文件
	public function clear_cache(){
		$step = $this->_get("step");
		$forderPathArr = array();
		$tip = "";
		$nextStep = 0;
		
		if($step == 1){	//STEP1.....删除Temp文件夹里所有的文件
			$forderPathArr[0] = "./core/Runtime/Temp/";
			$tip = "清除Temp缓存文件成功！";
			$nextStep = 2;
		}elseif($step == 2){	//STEP2.....删除Logs文件夹里所有的文件
			$forderPathArr[0] = "./core/Runtime/Logs/";
			$tip = "清除Logs日志文件成功！";
			$nextStep = 3;
		}elseif($step == 3){	//STEP3.....删除Data文件夹里所有的文件
			$forderPathArr[0] = "./core/Runtime/Data/";
			$tip = "清除Data日志文件成功！";
			$nextStep = 4;
		}elseif($step == 4){	//STEP4.....删除Cache文件夹里所有的文件
			$forderPathArr[0] = "./core/Runtime/Cache/Home/";
			$forderPathArr[1] = "./core/Runtime/Cache/Center/";
			$tip = "清除Cache缓存文件成功！";
		}
		if(empty($forderPathArr)){
			redirect(__APP__."/center/frame/index/");
			return ;
		}
		
		foreach ($forderPathArr as $forderPath){
			$fileList = CommonUtil::getFileList($forderPath);
			foreach ($fileList as $file){
				CommonUtil::deleteFile($forderPath.$file);
			}
		}
		$this->assign("tip",$tip);
		$this->assign("nextStep",$nextStep);
		$this->display();
		
	}
	
	//清除Runtime文件夹下的所有文件
	public function clear_temp(){
		
		$forderPath = "./uploads/temp/";
		$fileList = CommonUtil::getFileList($forderPath);
		
		foreach ($fileList as $file){
			CommonUtil::deleteFile($forderPath.$file);
		}
		$this->display();
		
	}
	
}